package com.bawei.bydayzg_two.adapter

import android.widget.RatingBar
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bawei.base.bean.GoodsPlItem0
import com.bawei.bydayzg_two.R
import com.bawei.bydayzg_two.Utils.GildUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class Pladapter:BaseQuickAdapter<GoodsPlItem0,BaseViewHolder>(R.layout.item_pl) {
    override fun convert(holder: BaseViewHolder, item: GoodsPlItem0) {
        GildUtils.loadYuan(context,item.avatar,holder.getView(R.id.pl_iv))
        holder.setText(R.id.pl_tv,item.nickname)
        holder.setText(R.id.pl_time,item.createTime)
        holder.getView<RatingBar>(R.id.pl_rb).rating = item.score.toFloat()
        holder.setText(R.id.pl_count,item.comment)
        //评论图片
        if (item.pics.size > 0 && item.pics[0]!= ""){
            //找到rv
            val rv  = holder.getView<RecyclerView>(R.id.pl_rv_img)
            //
            val imgAdapter = ImgAdapter()
            imgAdapter.data.addAll(item.pics)
            //
            rv.adapter = imgAdapter
            rv.layoutManager = GridLayoutManager(context,3)
        }
    }
}

//
class ImgAdapter :BaseQuickAdapter<String,BaseViewHolder>(R.layout.item_pl_img){
    override fun convert(holder: BaseViewHolder, item: String) {
        GildUtils.loadImg(context,item,holder.getView(R.id.img_iv))
    }
}